package com.yuejian_06.yuejian_06.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.yuejian_06.yuejian_06.R;
import com.yuejian_06.yuejian_06.activity.OrderInfoActivity;
import com.yuejian_06.yuejian_06.activity.OrdercInfoActivity;
import com.yuejian_06.yuejian_06.bean.OrderCourseBean;
import com.yuejian_06.yuejian_06.bean.OrderListBean;

import java.util.List;

/**
 * Created by __ZL__ on 2017/11/8.
 */

public class OrderCourseAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List mDataList;
    private LayoutInflater mLayoutInflater;
    public OrderCourseAdapter(Context mContext, List mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v =mLayoutInflater.from(parent.getContext()).inflate(R.layout.olccardview,parent,false);
        return new OrderCourseAdapter.ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder,int position) {
        final OrderCourseBean entity =(OrderCourseBean) mDataList.get(position);
        if (null == entity)
            return;
        OrderCourseAdapter.ViewHolder viewHolder = (OrderCourseAdapter.ViewHolder) holder;
        viewHolder.sign_id.setText(entity.getSign_id());
        //String p = String.valueOf(entity.getPrice());
        viewHolder.name.setText(entity.getName());
        viewHolder.price.setText(entity.getPrice());
        viewHolder.starttime1.setText(entity.getStarttime1());
        viewHolder.stoptime.setText(entity.getStoptime());
        viewHolder.intro.setText(entity.getIntro());
        if (!"".equals(entity.getPic()))
            Picasso.with(mContext).load("http://10.0.2.2/yuejian/Public/coursepics/"+entity.getPic()).into(viewHolder.pic);
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext,OrdercInfoActivity.class);
                intent.putExtra("sign_id",entity.getSign_id()+"");
                intent.putExtra("name",entity.getName()+"");
                intent.putExtra("price",entity.getPrice()+"");
                intent.putExtra("starttime1",entity.getStarttime1()+"");
                intent.putExtra("stoptime",entity.getStoptime()+"");
                intent.putExtra("intro",entity.getIntro()+"");
                intent.putExtra("pic",entity.getPic()+"");
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        private TextView sign_id,name,price,starttime1,stoptime,intro;
        private ImageView pic;
        public ViewHolder(View itemView) {
            super(itemView);
            sign_id = (TextView) itemView.findViewById(R.id.sign_id);
            name = (TextView) itemView.findViewById(R.id.name);
            price = (TextView) itemView.findViewById(R.id.price);
            starttime1 = (TextView) itemView.findViewById(R.id.starttime1);
            stoptime = (TextView) itemView.findViewById(R.id.stoptime);
            intro = (TextView) itemView.findViewById(R.id.intro);
            pic = (ImageView) itemView.findViewById(R.id.pic);
        }
    }
}